import { RootStateTypes, RoutesListState } from 'store/interface/index'
import { Module } from 'vuex'
import { AppRouteRecordRaw } from '../interface/index'

const routesListModule: Module<RoutesListState, RootStateTypes> = {
  namespaced: true,
  state: {
    routesList: [
      {
        meta: {
          icon: '',
          title: '首页'
        },
        name: 'Home',
        path: '/home'
      },
      {
        path: '/notice',
        name: 'notice',
        meta: {
          title: '消息'
        },
        children: [
          {
            path: '/notice/messageNotice',
            name: 'MessageNotice',
            meta: {
              title: '消息通知'
            }
          },
          {
            path: '/notice/list',
            name: 'NoticeList',
            meta: {
              title: '通知列表'
            }
          }
        ]
      }
    ]
  },
  mutations: {
    // 设置路由，菜单中使用到
    getRoutesList(state: any, data: Array<AppRouteRecordRaw>) {
      state.routesList = data
    }
  },
  actions: {
    // 设置路由，菜单中使用到
    async setRoutesList({ commit }, data: Array<AppRouteRecordRaw>) {
      commit('getRoutesList', data)
    }
  }
}

export default routesListModule
